<?php
/*
 * @Author: zls 3292844045@qq.com
 * @Date: 2022-05-25 20:48:34
 * @LastEditors: zls 3292844045@qq.com
 * @LastEditTime: 2022-05-27 00:34:12
 * @FilePath: \CUCCL\php\female_cloths.php
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
    include_once('connect.php');
    
    $search_msg = $_GET['search_msg'];
    $page = $_GET['page'];
    $num = $_GET['num'];
    $key = $_GET['key'];
    $sort = $_GET['sort'];
    
    //  $num = 6;
    // $page = 6;
    
    // $search_msg = '';
    // $key = 'cloths_prices';
    // $sort = 'asc';

    //查询数据库中所有的商品
    //1.分页显示所有商品
    if($num && $page){
        //查询一共有多少条数据
        $sql = "select count(*) page_len from female_cloths where cloths_type like '%$search_msg%'";
        $data = mysqli_query($conn, $sql);
        $arr = mysqli_fetch_array($data);
        //拿到商品数量
        $page_len = $arr['page_len'];

        //每一页的起始位置
        $start = ($page - 1) * $num;
      
        if($key === 'cloths_prices'){
            $sql2 = "select * from female_cloths where cloths_type like '%$search_msg%' limit $start, $num";
            $sql1 = "select * from ($sql2) as myTable order by $key $sort";
            // var_dump(1);
        }else{
            $sql1 = "select * from female_cloths where cloths_type like '%$search_msg%' order by $key $sort limit $start, $num";
            
        }
        $data1 = mysqli_query($conn, $sql1);
        $list = [];
        $res = [];
        while($info = mysqli_fetch_array($data1)){
            $arr = [];
            $arr['cloths_id'] = $info['cloths_id'];
            $arr['cloths_name'] = $info['cloths_name'];
            $arr['cloths_type'] = $info['cloths_type'];
            $arr['cloths_color'] = $info['cloths_color'];
            $arr['cloths_size'] = $info['cloths_size'];
            $arr['cloths_prices'] = $info['cloths_prices'];
            $arr['cloths_img'] = $info['cloths_img'];
            // $arr['goods_makeup'] = $info['goods_makeup'];
            array_push($list, $arr);
        }

        if($list){
            
            $res['status'] = true;
            $res['msg'] = '分页成功';
            $res['length'] = $page_len;
            $res['list'] = $list;
        }else{
            $res['status'] = false;
            $res['msg'] = '分页失败';
        }
    }
    
    echo(json_encode($res));

?>